package org.aersoft.jokebook.fragments;

import java.util.ArrayList;

import org.aersoft.jokebook.R;
import org.aersoft.jokebook.beans.ItemBean;
import org.aersoft.jokebook.core.Constants;
import org.aersoft.jokebook.core.GoogleAccount;
import org.aersoft.jokebook.dao.AppDAO;
import org.aersoft.jokebook.dao.api.IAppDAO;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

/**
 * Fragment class for main content.
 * @see {@link br.com.jokebook.activities.MainActivity}
 */
public class MainFragment extends Fragment {

	/**
	 * Constructor method of class.
	 */
	public MainFragment() {}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_main, container, false);

		IAppDAO appDAO = new AppDAO().getContext(getActivity());
		ArrayList<ItemBean> categoryArray = appDAO.getJokeAllCategories();
		appDAO.close();

		Button button1 = (Button) rootView.findViewById(R.id.button1);
		button1.setText(categoryArray.get(0).getCategoryName());
		Button button2 = (Button) rootView.findViewById(R.id.button2);
		button2.setText(categoryArray.get(1).getCategoryName());
		Button button3 = (Button) rootView.findViewById(R.id.button3);
		button3.setText(categoryArray.get(2).getCategoryName());
		Button button4 = (Button) rootView.findViewById(R.id.button4);
		button4.setText(categoryArray.get(3).getCategoryName());
		Button button5 = (Button) rootView.findViewById(R.id.button5);
		button5.setText(categoryArray.get(4).getCategoryName());
		Button button6 = (Button) rootView.findViewById(R.id.button6);
		button6.setText(categoryArray.get(5).getCategoryName());
		TextView username = (TextView) rootView.findViewById(R.id.nomeUsuario);
		GoogleAccount googleUser = new GoogleAccount(getActivity());
		username.setText(googleUser.getUsername() + Constants.EXCLAMATION);
		return rootView;
	}
}
